import getFont from "../../../utils/getFont";
const getNewFont = (font, fontSize) => {
    const fontObj = getFont(font);
    const newFont = [];
    newFont.push(fontObj.fontWeight);
    newFont.push(fontObj.fontStyle);
    newFont.push(fontSize);
    newFont.push(fontObj.fontFamily);
    return newFont.join(' ');
}
export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        const { sheet, selections, _oldFont, fontSize } = options;
        sheet.suspendPaint();
        if (isUndo) {
            selections.forEach(range => {
                for (let row = range.row, i = 0; i < range.rowCount; i++ , row++) {
                    for (let col = range.col, j = 0; j < range.colCount; j++ , col++) {
                        const cell = sheet.getCell(row, col);
                        cell.font(_oldFont[row][col]);
                    }
                }
            });
        } else {
            selections.forEach(range => {
                for (let row = range.row, i = 0; i < range.rowCount; i++ , row++) {
                    for (let col = range.col, j = 0; j < range.colCount; j++ , col++) {
                        const cell = sheet.getCell(row, col);
                        const oldFont = cell.font();
                        if (!options._oldFont) {
                            options._oldFont = {};
                        }
                        if (!options._oldFont[row]) {
                            options._oldFont[row] = {};
                        }
                        options._oldFont[row][col] = oldFont;
                       
                        const newFont = getNewFont(oldFont, `${fontSize}px`);
                        cell.font(newFont);
                    }
                }
            });
        }
        sheet.resumePaint();
    }
};